local extension=Package("pokestart")
extension.extensionName="jbs2"
local U = require "packages/utility/utility"
local T = require "packages/jbs/record/Theorem"
local Pe=require "packages/jbs2/pokgame/pokegegine"
extension.game_modes_whitelist={"jbsaola_mode"}
local function getKeys(tbl)
  local keys = {}
  for k, _ in pairs(tbl) do
      table.insert(keys, k)
  end
  return keys
end

local function getValue(tbl)
  local keys = {}
  for _, v in pairs(tbl) do
      table.insert(keys, v)
  end
  return keys
end

Fk:loadTranslationTable{
    ["pokestart"]="poke-启航",
    ["jbs2"]="泛桌游",
   
    
}



local siguang=fk.CreateTriggerSkill{
    name ="poke__siguang" ,
    anim_type = "offensive",
    events = {"fk.ssss"},
    on_use = function(self, event, target, player, data)
    local room = player.room
    local pow=150
    Pe.causedamage(player,target,self)

    end,
 
}
Pe.setproperty(siguang)

local xuanjia=fk.CreateTriggerSkill{
    name ="poke__xuanlingjia" ,
    anim_type = "offensive",
    events = {"fk.ssss"},
    on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"@poke_xuanlingjia-effectround",3)
    end,
    refresh_events = {fk.DamageInflicted},
    can_refresh = function(self, event, target, player, data)
        return target == player and player:getMark("@poke_xuanlingjia-effectround")>0
      end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        data.damage = data.damage//2
        if Pe.random(0.5) then
            Pe.changePowerlvs(data.from,nil,{-1})

        end
      end,
 
}

Pe.setproperty(xuanjia,{0,2,0,0,0,2})

local jufeng=fk.CreateTriggerSkill{
  name ="poke__jufeng" ,
  anim_type = "offensive",
  events = {"fk.ssss"},
  on_use = function(self, event, target, player, data)
  local room = player.room
  local pow=self.pow or 50
  Pe.causedamage(player,target,self)
  Pe.changePowerlvs(player,{"shot","crit"},{1})

  end,

}

local shilingpo=fk.CreateTriggerSkill{
  name ="poke__shilingpo" ,
  anim_type = "offensive",
  events = {"fk.ssss"},
  on_use = function(self, event, target, player, data)
  local room = player.room
  local pow=self.pow or 50
  Pe.causedamage(player,target,self)
  end,
  refresh_events = {fk.Damage},
  can_refresh = function(self, event, target, player, data)
      return target == player and data.damage and data.skillName=="poke__shilingpo"
    end,
  on_refresh = function(self, event, target, player, data)
      local room = player.room
      room:recover({
        who = player,
        num = (data.damage*0.3)//1,
        recoverBy = player,
        skillName = self.name

      })
    end,

}

Pe.setproperty(shilingpo,{150,0.9,0.3,1,1,0})

local nizhuan=fk.CreateTriggerSkill{
  name ="poke__nizhuan" ,
  anim_type = "offensive",
  events = {"fk.ssss"},
  on_use = function(self, event, target, player, data)
  local room = player.room
  local pow=self.pow or 50
  Pe.causedamage(player,target,self)
  local mark={"atk","def","spe","shot","miss","crit"}
  --获取增益属性
  local marks={}
  for i,str in ipairs(mark) do
    local currentlv=Pe.getPowerlv (target,str)
    if currentlv>0 then marks[str]=currentlv end
  end
  local str=getKeys(marks)
  local nums=getValue(marks)
  local bnums=table.map(nums,function (n) return -n 
    
  end)
  if Pe.random(0.2) then 
    Pe.changePowerlvs(player,str,nums)
  end
  Pe.changePowerlvs(target,str,bnums)

  end,
}

Pe.setproperty(shilingpo,{50,0.95,0.2,1,1,1})


--威力
jufeng.pow=100
--命中率
jufeng.hitrate=0.85
--暴击率
jufeng.critrate=0.2
--技能类型1为攻击,0为属性
jufeng.type=1
--是否为自己0为自己

jufeng.istoself=1

jufeng.first=0
local mark={"atk","def","spe","shot","miss","crit"}

Fk:loadTranslationTable{
  ["atk"]="攻击",
  ["def"]="防御",
  ["spe"]="速度",
  ["shot"]="命中",
  ["miss"]="闪避",
  ["crit"]="暴击",

}


Fk:addSkill(siguang)

T.translate("poke__siguang","破坏死光")
T.translate("@poke_xuanlingjia-effectround","玄灵甲")
T.translate("#pokemon_changePower_log","%from 的%arg提升了%arg2 级！ ")
T.translate("#pokemon_crit_log","打出了致命一击！")

local qilingwang=Pe.creaternewpokemon({extension,"poke__qilingwang","wei",511},{"奇灵王","帝王轩辕"}
,{316,276,266,{"poke__xuanlingjia","poke__shilingpo","poke__nizhuan","poke__jufeng"}})

qilingwang:addSkill(xuanjia)
qilingwang:addSkill(jufeng)
qilingwang:addSkill(shilingpo)
qilingwang:addSkill(nizhuan)
--qilingwang.hidden=true

T.translate("jbs_makechans","接龙")
T.translate(":jbs_makechans",[[由一名玩家开始打出一张牌，然后从其下家开始依次打出一张与上家所打出牌花色或点数相同的牌。]])



T.translate("poke__xuanlingjia","玄灵甲")
T.translate(":poke__xuanlingjia","【属性】先制+2，开启持续3回合的玄灵甲，拥有玄灵甲时受到伤害减半且有50%的几率使敌人降低全属性1级。")
T.translate("poke__shilingpo","噬灵破")
T.translate(":poke__shilingpo","【威力150】造成伤害的30%用于回复自身。")
T.translate("poke__nizhuan","灵之逆转")
T.translate(":poke__nizhuan",[[【威力50】20%的几率复制对手的增益属性，然后清除对手所有能力提升。]])
T.translate("poke__jufeng","飓风雷电")
T.translate(":poke__jufeng","【威力100】命中后提升命中和暴击1级。")


local ruiersi=Pe.creaternewpokemon({extension,"poke__ruiersi","wei",491},{"瑞尔斯","斗战武神"}
,{336,256,306,{"poke__birishiyue","poke__fenglinghuoshan","poke__shirupozhu","poke__xushidaifa"}})

local birishiyue=fk.CreateTriggerSkill{
  name ="poke__birishiyue" ,
  anim_type = "offensive",
  events = {"fk.ssss"},
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"@poke_shiyue-effectround",3)
    end,
    refresh_events = {fk.RoundEnd},
    can_refresh = function(self, event, target, player, data)
        return player:getMark("@poke_shiyue-effectround")>0
      end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        local n=math.min(player.maxHp//3,player:getLostHp())
        room:recover({
          who = player,
          num = n,
          recoverBy = player,
          skillName = self.name
        })
        local t=Pe.choicetarget(room,player,1)
        room:damage{
          from = player,
          to = t,
          damage = n,
          skillName=self.name
      }
      end,
}
T.skilltranslate("poke__birishiyue",{"蔽日食月","【属性】使用后三回合每回合回复自身体力的1/3，并对敌人造成等同于回复值的伤害。"})
Pe.setproperty(birishiyue,{0,2,0,0,0,0})

local fenglinghuoshan=fk.CreateTriggerSkill{
  name ="poke__fenglinghuoshan" ,
  anim_type = "offensive",
  events = {"fk.ssss"},
  on_use = function(self, event, target, player, data)
  local room = player.room
  local pow=self.pow or 50
  Pe.causedamage(player,target,self)
  local mark={"atk","def","spe","shot","miss","crit"}
  --获取增益属性
  local marks={}
  for i,str in ipairs(mark) do
    local currentlv=Pe.getPowerlv (player,str)
    if currentlv<0 then marks[str]=currentlv end
  end
  local str=getKeys(marks)
  local nums=getValue(marks)
  local bnums=table.map(nums,function (n) return -n 
  end)
  Pe.changePowerlvs(target,str,bnums)
  end,
  
  

}
T.skilltranslate("poke__fenglinghuoshan",{"风林火山","【威力150】容易暴击，命中后解除自身能力下降状态。"})

Pe.setproperty(fenglinghuoshan,{150,0.9,0.4,1,1,0})

local shirupozhu=fk.CreateTriggerSkill{
  name ="poke__shirupozhu" ,
  anim_type = "offensive",
  events = {"fk.ssss"},
  on_use = function(self, event, target, player, data)
  local room = player.room
  Pe.changePowerlvs(player,{"atk","spe","shot"},{2,1,1})
  end,
  

}
T.skilltranslate("poke__shirupozhu",{"势如破竹","【属性】使用后提升自身攻击2级，速度和命中各1级。"})
Pe.setproperty(shirupozhu,{0,2,0,0,0,0})

local xushidaifa=fk.CreateTriggerSkill{
  name ="poke__xushidaifa" ,
  anim_type = "offensive",
  events = {"fk.ssss"},
  on_use = function(self, event, target, player, data)
  local room = player.room
  local n=player:getMark(self.name.."-round")
  room:damage{
    from = player,
    to = target,
    damage = n,
    skillName=self.name
}
  end,
  refresh_events = {fk.Damaged},
  can_refresh = function(self, event, target, player, data)
      return target==player and player:hasSkill(self)
    end,
  on_refresh = function(self, event, target, player, data)
      local room = player.room
      room:setPlayerMark(player,self.name.."-round",data.damage)
    end,
  

}
T.skilltranslate("poke__xushidaifa",{"蓄势待发","【威力0】先制-1，对对手造成本回合自身受到的伤害。"})
T.translate("@poke_shiyue-effectround","吃月亮")
Pe.setproperty(xushidaifa,{0,2,0,1,1,-1})

ruiersi:addSkill(birishiyue)
ruiersi:addSkill(fenglinghuoshan)
ruiersi:addSkill(shirupozhu)
ruiersi:addSkill(xushidaifa)
--ruiersi.hidden=true


return extension